library(dplyr)

# 1 male, 2 female
# age group <20, 20-45, 45-60, >60
# treatment: type 1, 2, control

treatment = c(rep(1,20),rep(2,20),rep(3,20))
tr1 = ifelse(treatment==1,1,0) 
tr2 = ifelse(treatment==2,1,0) 
tr_c = ifelse(treatment==3,1,0) 
gender_box = c(1,2)
age = round(rnorm(60,25,2))
gender = sample(gender_box,60,replace=TRUE)
score = gender*30+age*15+tr1*70+tr2*35+rnorm(60,0,25)
score = round(45+(score-min(score))/(max(score)-min(score))*55,1)

df = data.frame(age=age,gender=factor(gender),group=factor(treatment),score=score)
fit_group = aov(score~group,data=df)
fit_gender = aov(score~group+gender,data=df)

library(haven)
write_sav(df,file.path("data","ch5_exe_2.sav"))


